Skip to content

Conversation

@tltsaia
Copy link

@tltsaia tltsaia commented Nov 26, 2025

Summary

Fixed an issue where only the first content item was returned when an MCP server sends multiple content items.

Problem

Current code only returns the first content item (line 67):

return res.Content[0].(mcp.TextContent).Text, nil

This causes data loss when MCP server returns multiple content items like:

{
  "content": [
    { "type": "text", "text": "First part" },
    { "type": "text", "text": "Second part" }
  ]
}

Only "First part" is returned, "Second part" is lost.

Solution

Modified the Call() method to iterate through all content items:

var texts []string
for _, content := range res.Content {
    if textContent, ok := content.(mcp.TextContent); ok {
        texts = append(texts, textContent.Text)
    }
}
return strings.Join(texts, "\n"), nil

Changes

  • ✅ Handles multiple content items correctly
  • ✅ Backward compatible (works with single item)
  • ✅ Follows MCP specification
  • ✅ No data loss

Thanks for this great adapter! 🙏

- Modified Call() method to iterate through all Content items
- Join multiple TextContent with newline separator
- Prevents data loss when MCP server returns multiple content items
@i2y
Copy link
Owner

i2y commented Nov 26, 2025

@tltsaia Thanks for the PR! The logic looks correct. Could you please:

  1. Run go fmt ./... to fix the indentation (Go uses tabs, not spaces)
  2. Add "strings" to the import block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants